<!DOCTYPE HTML>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("WebSocket: Test client-initiated close. After WebSocket.close() any message from server must be discarded by WebSocket stack according to the new WebSocket API. See http://webkit.org/b/85934.");

window.jsTestIsAsync = true;

var ws = new WebSocket("ws://127.0.0.1:8880/client-close");
var closeEvent;
var receivedMessage;

ws.onopen = function()
{
    debug("Connected");
    ws.close();
};

ws.onmessage = function(messageEvent)
{
    debug("Message should have been ignored: " + messageEvent.data);
    receivedMessage = messageEvent.data;
};

ws.onclose = function(event)
{
    debug("Closed");
    closeEvent = event;
    shouldBeUndefined("receivedMessage");
    shouldBeEqualToString("closeEvent.reason", "close_frame[:2]='88 80'");
    shouldBeTrue("closeEvent.wasClean");
    finishJSTest();
};

</script>
</body>
</html>
